﻿using System;
using BLL.Access;
using System.Data;

namespace Web.Pages.YongShui.ShuiPingHGL
{
    public partial class ShuiPingHengCX : BasePage
    {
        #region 属性

        /// <summary>
        /// 记录查询结果集
        /// </summary>
        private DataTable dtSource
        {
            get
            {
                return ViewState["dtSource"] as DataTable;
            }
            set
            {
                ViewState["dtSource"] = value;
            }
        }

        /// <summary>
        ///当前操作项ID
        /// </summary>
        private int SHUIPINGHCXID
        {
            get
            {
                return Convert.ToInt32(ViewState["SHUIPINGHCXID"]);
            }
            set
            {
                ViewState["SHUIPINGHCXID"] = value;
            }
        }

        /// <summary>
        /// 水量年
        /// </summary>
        private int ShuiLiangN
        {
            get
            {
                return Convert.ToInt32(ViewState["_ShuiLiangN"]);
            }
            set
            {
                ViewState["_ShuiLiangN"] = value;
            }
        }

        /// <summary>
        /// 水量月
        /// </summary>
        private int ShuiLiangM
        {
            get
            {
                return Convert.ToInt32(ViewState["_ShuiLiangM"]);
            }
            set
            {
                ViewState["_ShuiLiangM"] = value;
            }
        }

        #endregion

        #region 变量

        /// <summary>
        /// 数据访问操作类
        /// </summary>
        SpHelper _spHelper = new SpHelper();

        #endregion

        #region 事件

        /// <summary>
        /// 加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitControl();
                LoadData(true);
            }
            else
            {
                LoadData(false);
            }

        }

        /// <summary>
        /// 查询按钮事件
        /// </summary>
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            LoadData(true);
        }

        #endregion

        #region 方法

        /// <summary>
        /// 初始化控件
        /// </summary>
        private void InitControl()
        {
            //加载水量年
            concmbY.Items.Add("","");
            for (int i = DateTime.Now.Year; i > DateTime.Now.AddYears(-10).Year; i--)
            {
                concmbY.Items.Add(i.ToString(),i.ToString());                
            }
            concmbY.SelectedIndex = 0;
        }

        /// <summary>
        /// 查询数据
        /// </summary>
        /// <param name="reGet">是否重新读取数据库</param>
        private void LoadData(bool reGet)
        {
            if (reGet)
            {
                string condition = "1=1";
                if(this.contxtYongHuH.Text!="")
                {
                    condition = condition + " and S_YONGHUH like '" + this.contxtYongHuH.Text + "%'";
                }
                if (this.contxtYongHuM.Text != "")
                {
                    condition = condition + " and S_YONGHUM='" + this.contxtYongHuM.Text + "'";
                }
                if (this.contxtYongHuDiZhi.Text != "")
                {
                    condition = condition + " and S_DIZHI like '%" + this.contxtYongHuDiZhi.Text + "%'";
                }
                condition = condition + " and i_type=" + this.concmbzhuangtai.Value.ToString();
                if(this.concmbY.SelectedIndex!=0)
                {
                    condition = condition + " and EXTRACT(year FROM D_BEIANRQ)=" + this.concmbY.Value;
                }
                if (this.concmbM.SelectedIndex != 0)
                {
                    condition = condition + " and EXTRACT(month FROM D_BEIANRQ)=" + this.concmbM.Value;
                }
                if(this.concmbNianShuiLiangRange.SelectedIndex!=0&&this.contxtShuiLiangFanWei.Text!="")
                {
                    condition = condition + " and s_niansl" + this.concmbNianShuiLiangRange.Value.ToString() + this.contxtShuiLiangFanWei.Text;
                }
                this.dtSource = this._spHelper.P_YS_GETSHUIPINGH(condition).Tables[0];
                this.txtShuiPingHengHuShu.Text = this.dtSource.Rows.Count.ToString();
            }
            this.gvShuiPingHengCX.DataSource = this.dtSource;
            this.gvShuiPingHengCX.DataBind();
        }
        #endregion       

    }
}